// import htmlParser from '@/common/js/html-parser';
// import {
// 	Weixin
// } from '@/common/js/wx-jssdk.js';
// import Config from 'common/js/config.js';
import DownloadApp from '@/components/global/download-app.vue';
export default {
	data() {
		return {
			collection_type: 0, // 判断是否收藏
			shareObj: null,
			shareContent: null
		}
	},
	onLoad(data) {},
	onShow() {
		if (this.$Router.queryObj().id) {
			this.initCall()
		}
	},
	onHide() {},
	components:{
		DownloadApp
	},
	methods: {
		initCall() {
			let token = uni.getStorageSync('token')
			if (token) {
				this.$Apis.setIscollect({
					sku_id: this.$Router.queryObj().id
				}).then(res => {
					this.collection_type = res
				})
			}
			this.$Apis.topicgoods({
				id: this.$Router.queryObj().id
			}).then(success => {
				this.shareContent = {
					title: success.goods_sku_detail.sku_name, // 分享标题
					shareObjectDesc: '醒目购，够醒目，醒目就购啦！', // 分享描述
					thumbUrl: success.goods_sku_detail.sku_image // 分享图标
				}
				this.shareObj = success.goods_sku_detail
			});
		},
		scollectBtn() {
			if (!this.$Utils.isLoginCall()) return false;
			// 判断一下是否能拿到商品id
			if (this.$Router.queryObj().id) {
				// 取消收藏
				if (this.collection_type == 1) {
					this.$Apis.deleteGoodsCollect({
						sku_id: this.$Router.queryObj().id,
						type: 'goods'
					}).then(res => {
						this.collection_type = 0
						this.$Utils.tip('商品取消收藏成功')
					})
				} else { // 添加收藏
					this.$Apis.addGoodsCollect({
						sku_id: this.$Router.queryObj().id,
						type: 'goods'
					}).then(res => {
						this.$Utils.tip('商品添加收藏成功')
						this.collection_type = 1
					})
				}
			}
		},
		shareBtn() {
			// #ifdef H5
			if (this.isNativeApp()) {
				var urlnews = location.href.indexOf("?") == -1 ? "?" : "&"
				this.$Sdk.share(this.shareObj.sku_name, location.href+urlnews+'source_member='+ this
				.userInfo.member_id, this.shareObj.sku_image)
			} else {
				this.showFenXiang = !this.showFenXiang
				console.log('H5分享',this.showFenXiang);
			}
			// #endif
			// #ifdef MP-WEIXIN
				this.showFenXiang = !this.showFenXiang
				console.log('小程序分享',this.showFenXiang);
			// #endif
		},
		toStoreim() {
			if (!this.$Utils.isLoginCall()) return false;
			this.$Router.push({
				path: '/chatPages/storeim/storeim',
				query: {
					sku_id: this.shareObj.sku_id,
					site_id: this.shareObj.site_id
				}
			})
			// console.log('logthis.shareObj', this.shareObj.sku_id);
		}
	}
}
